home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_054 / miditools / getmidi.c next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  158 lines

  1. /****************************************************************************
  2.   
  3.    Author:  Fred Cassirer
  4.    Date:    January 24, 1987
  5.    
  6.    This program is placed in the public domain, and from what I understand
  7.    that means anyone can do whatever they want with it.   That's fine 
  8.    because they are fairly trivial anyway ...  If you can get someone to pay
  9.    you for them, you must be doing something right.
  10.  
  11.  ****************************************************************************/
  12. /*  compiler directives to fetch the necessary header files */
  13. #include <libraries/dos.h>
  14. #include <exec/types.h>
  15. #include <exec/exec.h>
  16. #include <devices/serial.h>
  17. #include <stdio.h>
  18. #include <ctype.h>
  19. #include <functions.h>
  20. #include "midi.h"
  21.  
  22. #undef NULL
  23. #define   NULL   ((void *)0)
  24.  
  25. extern long SetSignal();
  26.  
  27. breakcheck()
  28. {
  29.    if (SetSignal(0L,0L) & SIGBREAKF_CTRL_C )
  30.      return ( 1 );
  31.    else
  32.      return( 0 );
  33. }
  34.  
  35. breakreset()
  36. {
  37.    SetSignal(0L, SIGBREAKF_CTRL_C);
  38. }
  39.  
  40. /* this routine causes manx to use this Chk_Abort() rather than it's own */
  41. /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
  42. /* is zero).  Since we want to check for our own ^C's                    */
  43.  
  44. Chk_Abort()
  45. {
  46. return(0);
  47. }
  48.  
  49.  
  50. /* declarations for the serial stuff */
  51.  
  52. extern struct MsgPort *CreatePort();
  53. struct IOExtSer *Read_Request;
  54. static unsigned char rs_in[2];
  55.  
  56. struct IOExtSer *Write_Request;
  57. static unsigned char rs_out[2];
  58.  
  59. void initmidi()
  60. {
  61.  
  62. Read_Request = (struct IOExtSer *)AllocMem((long)sizeof(*Read_Request),MEMF_PUBLIC|MEMF_CLEAR);
  63. Read_Request->io_SerFlags = SERF_SHARED | SERF_RAD_BOOGIE;
  64. Read_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",0);
  65.  
  66. if(OpenDevice(SERIALNAME,NULL,Read_Request,NULL))
  67.    {
  68.    puts("Cant open Read device\n");
  69.    DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort);
  70.    FreeMem(Read_Request,(long)sizeof(*Read_Request));
  71.    exit(TRUE);
  72.    }
  73.  
  74. Read_Request->IOSer.io_Length = 1;
  75. Read_Request->IOSer.io_Data = (APTR) &rs_in[0];
  76. Read_Request->io_Baud = 31250;
  77. Read_Request->io_ReadLen = 8;
  78. Read_Request->io_WriteLen = 8;
  79. Read_Request->io_CtlChar = 1L;
  80. Read_Request->IOSer.io_Command = SDCMD_SETPARAMS;
  81. DoIO(Read_Request); 
  82. Read_Request->IOSer.io_Command = CMD_READ;
  83.  
  84. Write_Request = (struct IOExtSer *)AllocMem((long)sizeof(*Write_Request),MEMF_PUBLIC|MEMF_CLEAR);
  85. Write_Request->io_SerFlags = SERF_SHARED | SERF_RAD_BOOGIE;
  86. Write_Request->io_StopBits = 1;
  87. Write_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS",0);
  88. if(OpenDevice(SERIALNAME,NULL,Write_Request,NULL))
  89.    {
  90.    puts("Can't open Write device\n");
  91.    DeletePort(Write_Request->IOSer.io_Message.mn_ReplyPort);
  92.    FreeMem(Write_Request,(long)sizeof(*Write_Request));
  93.    DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort);
  94.    FreeMem(Read_Request,(long)sizeof(*Read_Request));
  95.    exit(TRUE);
  96.    }
  97.  
  98. Write_Request->IOSer.io_Command = CMD_WRITE;
  99. Write_Request->IOSer.io_Length = 1;
  100. Write_Request->IOSer.io_Data = (APTR) &rs_out[0];
  101. Write_Request->io_SerFlags = SERF_SHARED | SERF_XDISABLED;
  102.  
  103. BeginIO(Read_Request);
  104. breakreset();
  105.  
  106. }
  107.  
  108. void cleanup()
  109.       
  110. CloseDevice(Read_Request); 
  111. DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort);
  112. FreeMem(Read_Request,(long)sizeof(*Read_Request)); 
  113. CloseDevice(Write_Request);
  114. DeletePort(Write_Request->IOSer.io_Message.mn_ReplyPort);
  115. FreeMem(Write_Request,(long)sizeof(*Write_Request));
  116.  
  117.  
  118.    /************************************************************/
  119.   /* send midi data to the serial port                        */
  120.  /************************************************************/
  121.  
  122. int putmidi(ch)
  123. int ch;
  124. {
  125.  
  126.  rs_out[0] = ch;
  127.  DoIO(Write_Request);
  128.  return(ch);
  129.  
  130. }
  131.  
  132. /******************************************************/
  133. /*           This routine will return an unsigned     */
  134. /*                byte of midi data.                  */
  135. /******************************************************/
  136.  
  137. int getmidi()
  138. {
  139. int c;
  140.  
  141.     Wait( (1L << Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit)  
  142.          |  (SIGBREAKF_CTRL_C) );
  143.  
  144.     if(CheckIO(Read_Request))
  145.       {
  146.        WaitIO(Read_Request);
  147.        c=rs_in[0];
  148.        BeginIO(Read_Request);
  149.       }
  150.      else 
  151.       c = NON_MIDI_EVENT; 
  152.  
  153. return(c);
  154. }
  155.  
  156.